package com.woniuxy;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;

import java.util.Map;

/**
 * @Author: 马宇航
 * @Todo: 测试BeanFactory和ApplicationContext对象
 * @DateTime: 01/18/0018 上午 10:46
 * @Component: 成都蜗牛学苑
 **/
public class TestIOC {
    public static void main(String[] args) {

        //FileSystemResource 是通过绝对路径进行文件加载
        //BeanFactory beanFactory = new XmlBeanFactory(new FileSystemResource("C:\\Users\\ASUS\\Desktop\\85期的笔记\\java85classcode\\day02ioc\\src\\applicationContext.xml"));
        //ClassPathResource  项目路径下的文件加载
//        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
//        //T 泛型
//        Person jap1 = beanFactory.getBean("jap", Person.class);
//        Person jap2 = beanFactory.getBean("jap", Person.class);
//        System.out.println(jap1);
//        System.out.println(jap2);
//        jap1.eat();
        //第二种获取配置文件的方式 FileSystemXmlApplicationContext 同理
//        ApplicationContext applicationContext = new FileSystemXmlApplicationContext("C:\\Users\\ASUS\\Desktop\\85期的笔记\\java85classcode\\day02ioc\\src\\applicationContext.xml");
        // 通过项目路径找配置文件 ClassPathXmlApplicationContext
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        Person jap = applicationContext.getBean("jaap", Person.class);
//        System.out.println(jap);
//        jap.eat();

/*//       1. 通过配置文件配置静态方法的工厂
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        Person factoryCreateChinese = (Person) applicationContext.getBean("factoryCreateChinese");
        factoryCreateChinese.eat();*/
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext1.xml");
        Map mapMoney = applicationContext.getBean("mapMoney", Map.class);
        System.out.println(mapMoney);
    }
}
